using Android.Accounts;
using Android.Content;
using Android.Graphics;
using Android.Runtime;
using Android.Telecom;
using Android.Util;
using Android.Views;

using System;
using Game;

public class BallView : View
{
    MainGame game = new MainGame();
    Random random = new Random();
    int windowWidth;
    int windowHeight;

    public BallView(Context context) : base(context)
    {
        Android.Graphics.Rect wrect = new Android.Graphics.Rect();
        this.GetWindowVisibleDisplayFrame(wrect);
        windowWidth = wrect.Width() - 10;
        windowHeight = wrect.Height() - 30;
    }


    protected override void OnDraw(Canvas canvas)
    {
        game.Display(canvas, windowWidth, windowHeight);
        //base.OnDraw(canvas);
    }

    Color GetRandomColor()
    {        
        int red = random.Next(0, 255);
        int green = random.Next(0, 255);
        int blue = random.Next(0, 255);
        return Color.Argb(50, red, green, blue);
    }

    public override bool OnTouchEvent(MotionEvent e)
    {
        if(e.GetY() > windowHeight - 420)
        {
            int width = windowWidth / 6;
            int index = (int)(e.GetX() / width);
            game.DoAction(index);
            this.Invalidate();
        }

        return base.OnTouchEvent(e);
    }

}

